function getObjType(obj) {
    var toString = Object.prototype.toString;
    var map = {
        "[object Boolean]": "boolean",
        "[object Number]": "number",
        "[object String]": "string",
        "[object Function]": "function",
        "[object Array]": "array",
        "[object Date]": "date",
        "[object RegExp]": "regExp",
        "[object Undefined]": "undefined",
        "[object Null]": "null",
        "[object Object]": "object",
        "[object Symbol]": "symbol",
        "[object AsyncFunction]": "function",
    };
    return map[toString.call(obj)];
};

const isPromise = item => {
    return item && (typeof item.then == 'function');
}

async function emitBeforeEach(pack) {
    try {
        return await Promise.all([...pack._root._onBeforePlugins].map(fn => {
            return fn(pack);
        }))
    } catch (e) {
        console.error('emitBeforeEach>> ', e)
    }
}

async function emitAfterEach(pack) {
    try {
        return await Promise.all([...pack._root._onAfterPlugins].map(fn => {
            return fn(pack);
        }));
    }catch (e) {
        console.error('emitAfterEach>>', e)
    }
}

exports.getObjType = getObjType;
exports.isPromise = isPromise;
exports.emitBeforeEach = emitBeforeEach;
exports.emitAfterEach = emitAfterEach;
